您现在的位置是:首页 >PHP网站首页PHP

PHP图片压缩

简介我们在上传图片时,有时为了节省空间,不得不使用PHP压缩图片来处理要上传的图片,以达到为服务器减压的作用。而更是为了优化网页加载速度起到了更有效的作用。

imagecopyresampled( $dstImg, $srcImg, 0, 0, 0, 0, $dstWidth, $dstHeight, $srcWidth, $srcHeight ); imagecopyresized( $new, $img , 0, 0, 0, 0, $newWidth, $newHeight, $width, $height );

imagecopyresampled :速度较慢,对图片进行原样采集,还原度较高。 imagecopyresized: 速度较快,对图片进行压缩,占内存较小。

$file = '3.jpg';

list( $width, $height ) = getimagesize( $file );

$new = imagecreatetruecolor( 500, 500 ); $img = imagecreatefromjpeg( $file );

imagecopyresized( $new, $img , 0, 0, 0, 0, 500, 500, $width, $height );

imagejpeg( $new, '333.jpg');

imagedestroy($new); imagedestroy($img);

文章评论

Top